<?php

require_once __DIR__ . '/Request.php';

class WeApp {
    public $wxToken;

    const GetWxACodeUnlimitURL = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit';

    function __construct($wxToken) {
        $this->wxToken = $wxToken;
    }
    function getWxACodeUnlimit($scene, $page) {
        return Request::post_json(WeApp::GetWxACodeUnlimitURL . "?access_token={$this->wxToken}", json_encode(array(
            // 'access_token' => $wxToken,
            'scene' => $scene,
            'page' => $page
        )));
    }
    static function getOpenid($code, $appid, $appSecret) {
        $url = "https://api.weixin.qq.com/sns/jscode2session";
        // "?appid={$appid}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
        $requestResultJSON = Request::get($url, [
            'appid' => $appid,
            'secret' => $appSecret,
            'js_code' => $code,
            'grant_type' => 'authorization_code',
        ]);
        return json_decode($requestResultJSON, true);
    }
}
